﻿using System;
using BlueDot.Data.Core;
using BlueDot.Data.Core.Sql;
using CustomBusinessLogic.Data.Entities;
using ExampleConsole.Data.Mocks;

namespace CustomBusinessLogic
{
    internal class Program
    {
        #region private

        private static void Main(string[] args)
        {
            Console.WriteLine("Create and assign Provider");
            //For this example we do not need a real database so we created a "Mock" provider
            //we can now test our custom buisness logic and not worry about any external resources
            ProviderFactory.DefaultProvider = new MockDataProvider();

            Console.WriteLine("Create a new user");
            User user = new User()
            {
                FirstName = "Seumas",
                LastName = "VanMatre"
            };

            //we can also listen to the DataPersistance Pre and Post save events
            //these events are called no matter the type of entity being saved.  Using the Manager
            //attribute we can add custom logic for specific entity types
            DataPersistence.PreSaveNotification +=
              delegate(object sender, EntitySaveEventArgs e)
              {
                  Console.WriteLine("DataPersistance.PreSaveNotification called");
              };

            DataPersistence.PostSaveNotification +=
              delegate(object sender, EntitySaveEventArgs e)
              {
                  Console.WriteLine("DataPersistance.PostSaveNotification called");
              };

            Console.WriteLine("Save User");
            user.Save();

            Console.WriteLine("User has been saved");
            Console.ReadLine();
        }

        #endregion
    }
}